<template>
  <div class="Eqadmin">
    <!-- 设备管理 -->
    <house>
      <Table
        :tableArr="tableArr"
        :tableData="neiryArr2"
        :operationObj="operationObj"
        @deleteRow1="leteRow1"
        @deleteRow2="leteRow2"
      ></Table>
      <MaskVue
        ref="flage"
        type="wrap"
        :headright="false"
        QuXiao="续费"
        btnTitle="回收"
        @cancel="xf"
        @preservation="hs"
      ></MaskVue>
    </house>
    <ReceivingVue ref="flage1"></ReceivingVue>
  </div>
</template>

<script setup>
import { ref, reactive } from "vue";
import house from "../../components/hose.vue";
import Table from "../../components/Table.vue";
import MaskVue from "../../components/Mask.vue";

import { useRouter } from "vue-router";
import { equipmentInfoList } from "../../api/index.js";
import ReceivingVue from "../../components/Receiving.vue";
import { newTime } from "../../components/Method";
const router = useRouter();
const flage = ref(null);
const flage1 = ref(null);

const flageOne = ref(null);

const tableArr = ref({
  equipmentId: "设备编号",
  applyDate: "申请时间",
  leaseYear: "租借年份（年）",
  expirationDate: "到期时间",
  leaseStatus: "租借状态",
  address: "设备位置",
  title: "状态",
});

const iptObj = ref({
  title: "设备管理",
  userBool: false, //手机搜索框是否显示
  userTitle: "订单编号",
  userTel: "联系电话",
  userRegion: "",
  telrBool: false, //电话搜索框是否显示
  regionBool: false, //选项框是否显示
  userText: "请输入订单编号",
  telText: "请输入联系电话",
  regionText: "请选择内容",
  BtnBool: true,
});

const operationObj = ref({
  operation1: "查看详情",
  operation2: "回收",
  title1: "操作1", //操作标题
  title2: "操作2",
  type1: "primary", //button 类型
  type2: "primary",
  text1: false, // true 为文字类型
  text2: false,
  bool1: true, //操作是否显示
  bool2: true,
  row: false, //是否合并
});

const neiryArr = ref([]);
const neiryArr2 = ref([]);
const neiryArr3 = ref([]);

const tableArr1 = ref([
  "设备编号",
  "设备型号",
  "租借年份（年）",
  "申请时间",
  "到期时间",
  "设备位置",
  "申请时间",
  "租借年份（年）",
  "到期时间",
  "设备位置",
  "设备型号",
]);

const neiryArr1 = reactive({});

const leteRow1 = (index) => {
  neiryArr1.value = neiryArr.value[index];
  delete neiryArr1.value.btn1;
  delete neiryArr1.value.btn2;
  delete neiryArr1.value.type2;
  flage.value.open(neiryArr1.value, tableArr1.value);
  delete neiryArr1.value.equipmentCid;
  delete neiryArr1.value.leaseStatus;

  (neiryArr1.value.applyDate = newTime(
    "YYYY-MM-DD HH:MM",
    neiryArr.value[index].applyDate
  )),
    (neiryArr1.value.expirationDate = newTime(
      "YYYY-MM-DD HH:MM",
      neiryArr.value[index].expirationDate
    )),
    flage.value.open(neiryArr1.value, tableArr1.value);
};

const leteRow2 = (index) => {
  if (neiryArr.value[index].type2 !== "回收") {
    flage1.value.open();
  } else {
    router.push("/equipment/EqapplyFor");
  }
};

const xf = () => {
  console.log(111);
  router.push("/equipment/EqapplyFor");
};

const hs = () => {
  console.log(222);
  flage1.value.open();
};

equipmentInfoList()
  .then((res) => {
    neiryArr.value = res.data.data.items;

    neiryArr.value.forEach((item) => {
      neiryArr2.value.push({
        equipmentId: item.equipmentId,
        applyDate: newTime("YYYY-MM-DD", item.applyDate),
        expirationDate: newTime("YYYY-MM-DD", item.expirationDate),
        leaseYear: item.leaseYear,
        address: item.address,
      });
    });
  })
  .catch((res1) => {
    console.log(res1);
  });
</script>

<style lang="less" scoped>
.Eqadmin {
  height: 100%;
  width: 100%;
}
</style>
